/*--
 * Prefs.cs: Exposes commands for relating to the getting and setting of preferences.
 *--
 * For more information, please visit the Metashell Project site:
 *   http://code.google.com/p/metashell/
 *--
 * (c) 2006 Christopher E. Granade.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; exactly version 2
 * of the License applies to this software.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

using System;
using System.IO;
using Metashell.Core;
using Metashell.Core.Utility;

namespace Metashell.Commands.Basic {

	public class GetPref : ICommand {
				
		private Metashell.Core.Core core;
		
		public void RegisterCore(Metashell.Core.Core core_) {
			core = core_;
		}
		
		public string name {
			get { return "getpref"; }
		}
		
		public void Run(
			string parameters,
			Metadoc indoc,
			out Metadoc outdoc
		) {
			
			outdoc = XML.EncapsulateString(core.GetPreference(parameters, null));
			
		}

	}

	public class SetPref : ICommand {
				
		private Metashell.Core.Core core;
		
		public void RegisterCore(Metashell.Core.Core core_) {
			core = core_;
		}
		
		public string name {
			get { return "setpref"; }
		}
		
		public void Run(
			string parameters,
			Metadoc indoc,
			out Metadoc outdoc
		) {
			
			if (parameters.Trim().IndexOf(' ') == -1) {
				core.RaiseError("Usage: setpref preference value");
			}
			
			string trimparams = parameters.TrimStart(); 
			string pref = trimparams.Substring(0, trimparams.IndexOf(' ')),
			       newval = trimparams.Substring(trimparams.IndexOf(' ') + 1);
			
			core.SetPreference(pref, newval);
			
			outdoc = XML.EncapsulateString(null);
			
		}

	}
}